package com.example.publish_model;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.LogUtils;
import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAVideoEntity;

import java.lang.ref.WeakReference;
import java.util.concurrent.BlockingQueue;

public class ConsumerGift implements Runnable{
    private BlockingQueue<String> blockingQueue;
    private WeakReference<SVGAImageView> weakReference;
    private SVGAParser svgaParser;

    public ConsumerGift(BlockingQueue<String> blockingQueue, SVGAImageView svgaImageView,SVGAParser svgaParser) {
        this.blockingQueue = blockingQueue;
        weakReference = new WeakReference<>(svgaImageView);
        this.svgaParser = svgaParser;
    }

    @Override
    public void run() {
        try {
            String take = blockingQueue.take();
            LogUtils.e("出队:"+take);
            svgaParser.decodeFromAssets(take, new SVGAParser.ParseCompletion() {
                @Override
                public void onComplete(@NonNull SVGAVideoEntity svgaVideoEntity) {
                    weakReference.get().setVideoItem(svgaVideoEntity);
                    weakReference.get().stepToFrame(0, true);
                }

                @Override
                public void onError() {

                }
            });

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
